package br.com.lucasddaniel.merchanmobile.adapter;

import java.text.SimpleDateFormat;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import br.com.lucasddaniel.merchanmobile.R;
import br.com.lucasddaniel.merchanmobile.bean.PacoteArquivoBean;

public class PacotesRelatorioAdapter extends ArrayAdapter<PacoteArquivoBean> {
    private Context context = null;
    private List<PacoteArquivoBean> listPacotes = null;

    public PacotesRelatorioAdapter(Context context, int resource, List<PacoteArquivoBean> listPacotes) {
        super(context, resource, listPacotes);
        this.context = context;
        this.listPacotes = listPacotes;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.row_pacotes_relatorio, parent, false);

        if (listPacotes != null && listPacotes.size() != 0) {
            PacoteArquivoBean pacoteBean = (PacoteArquivoBean) listPacotes.get(position);
            if (pacoteBean != null) {
                TextView nomePacote = (TextView) rowView.findViewById(R.id_row_pacote.nome);
                TextView preco = (TextView) rowView.findViewById(R.id_row_pacote.preco);
                TextView dataHoraSaida = (TextView) rowView.findViewById(R.id_row_pacote.data);
                TextView transporte = (TextView) rowView.findViewById(R.id_row_pacote.transporte);
                TextView quantidade = (TextView) rowView.findViewById(R.id_row_pacote.quantidade);
                TextView total = (TextView) rowView.findViewById(R.id_row_pacote.total);
                TextView tipoDeMoeda = (TextView) rowView.findViewById(R.id_row_pacote.tipo_moeda);

                nomePacote.setText(pacoteBean.getNome());
                preco.setText(pacoteBean.getPreco() + "");
                if (pacoteBean.getTipoMoeda().equalsIgnoreCase("Dolar")) {
                    preco.setText(pacoteBean.getPrecoDolar() + "");
                }
                SimpleDateFormat sdfData = new SimpleDateFormat("dd/MM/yyyy HH:mm");
                dataHoraSaida.setText(sdfData.format(pacoteBean.getDataHoraSaida()));
                transporte.setText(pacoteBean.getTransporte());
                quantidade.setText(pacoteBean.getQuantidade() + "");
                total.setText(pacoteBean.getTotal() + "");
                tipoDeMoeda.setText(pacoteBean.getTipoMoeda());
                //                TableLayout myTable=new TableLayout(this);        
                //                TextView[][] myTextView=new TextView[3][3];
                //                myTable.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
                //                TableRow[] myRow=new TableRow[3];        
                //                for (int i = 0; i < 3; i++) {
                //                    myRow[i]=new TableRow(this);
                //                    myRow[i].setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));           
                //                    for (int j = 0; j < 3; j++) {               
                //                        myTextView[i][j]=new TextView(this);  
                //                        myTextView[i][j].setText("Your Text");
                //                        myRow[i].addView(myTextView[i][j]);
                //                    }   
                //                    myTable.addView(myRow[i]);
                //                }
                //                LinearLayout lin=(LinearLayout)findViewById(R.id.linLayout);
                //                lin.addView(myTable);
                //                passeioBean.setImg(imgChecked);
                //                txtViewNome.setText(passeioBean.getNome());
                //                txtQuantidade.setText(passeioBean.getQuantidade() + "");
                //                txtViewMotorista.setText(passeioBean.getMotorista());
                //                txtViewOperador.setText(passeioBean.getOperador());
                //                if (passeioBean.isChecked()) {
                //                    passeioBean.getImg().setVisibility(View.VISIBLE);
                //                } else {
                //                    passeioBean.getImg().setVisibility(View.INVISIBLE);
                //                }
            }
        }
        return rowView;
    }

    @Override
    public int getCount() {
        return super.getCount();
    }
}
